parser grammar BreakParser;

options {
  language = Java;
  tokenVocab = BreakLexer;
  backtrack = true;
}

@header {
  package practica8;
  import java.util.Hashtable;
}

@members {
    
    private ArrayList<RecognitionException> errors = new ArrayList<RecognitionException>();
    public ArrayList<RecognitionException> getErrors() {
       return errors;
    }
    @Override
    public void reportError (RecognitionException e) {
       String msg = getErrorMessage(e, getTokenNames());
       System.err.println(msg);
       errors.add(e);
    }
}


entrada [boolean cond_while]: (bucle_while[cond_while]|condicional_if[cond_while])*;

bucle_while [boolean cond_while]: w=WHILE c=condicion b=bloque[true];

condicional_if [boolean cond_while]: i=IF c=condicion b=bloque[cond_while];

condicion: PARENTESIS_A IDENT PARENTESIS_C;

bloque [boolean cond_while]: LLAVE_A (sentencias[cond_while])* LLAVE_C;

sentencias [boolean cond_while]: bucle_while[cond_while] | condicional_if[cond_while] | salir[cond_while];

salir [boolean cond_while]: BREAK PUNTO_COMA {if (cond_while)
                                                 System.out.println("Instruccion break ubicada dentro de bucle While");
                                              else
                                                 System.out.println("Instruccion break ubicada fuera de bucle While");};
